package org.bot.plugin.oa.event;

import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.bot.plugin.web.util.WebApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 沧月
 * @create 0013 2023/10/13 09:13
 * @description <OA 设置富文本框>
 */
@Component
@EventName("设置富文本值（OA）")
public class OaExtendSetEditorValue implements Events {

    @Autowired
    WebApi webApi;

    @Override
    public Object exec(FlowNode note, DataStorage data) {
        String metadata = note.getArg();
        String javaScript = "var id = $(\"div[x-metadata=" + metadata + "]\").find(\"div\").attr(\"id\");\n" +
                "UE.getEditor(id).setContent(arguments[0]);";
        return webApi.script(webApi.getWebDriver(note), javaScript, data.get(note.getDataIndex()));
    }

}
